/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// MemoryLeakDetector.h
//

#pragma once

#include "BaseDefine.h"

#ifdef WIN32
	#include <windows.h>
	#define _CRTDBG_MAP_ALLOC
	#include <stdlib.h>
	#include <crtdbg.h>
#else
#endif

/**
* @class MemoryLeakDetector
*  -
*/ 
class DEFLIB_EXTERN_CLASS CMemoryLeakDetector{
public:
	CMemoryLeakDetector(){
#ifdef _DEBUG
#ifdef WIN32
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF ); 		
#endif
#endif
	}

	void BreakAllocateNumber(long number){
#ifdef _DEBUG
#ifdef WIN32
		_crtBreakAlloc = number;
#endif
#endif
	}	

	~CMemoryLeakDetector(){
#ifdef _DEBUG
#ifdef WIN32
		_CrtDumpMemoryLeaks(); 
#endif
#endif
	}
};

#ifdef _DEBUG
#define RE_DEBUG_NEW	new( _CLIENT_BLOCK, __FILE__, __LINE__)

#ifndef NEW
	#define NEW RE_DEBUG_NEW
#endif

#else
#define RE_DEBUG_NEW
#endif

#ifndef NEW
#define NEW	new
#endif

#ifndef NEW
#define  NEW new
#endif
